package com.edu.elasticsearch.utils;

import java.math.BigDecimal;
import java.util.Random;

public class NumericalUtils {
	
	/**
	* @Description: 随机生成浮点数值 
	* @param min 最小值
	* @param max 最大值
	* @return double
	* @throws Exception   
	 */
    public static double nextDouble(final double min, final double max) throws Exception {
        if (max < min) {
            throw new Exception("min < max");
        }
        if (min == max) {
            return min;
        }
        double random = min + ((max - min) * new Random().nextDouble());
        BigDecimal latLon = new BigDecimal(random);
        return latLon.setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
	
    /**
    * @Description: 生成随机中文 
    * @param len 个数
    * @return  String
     */
    public static String getRandomChiness(int len){
		String ret = "";
		for (int i = 0; i < len; i++) {
			String str = null;
			int hightPos, lowPos; // 定义高低位
			Random random = new Random();
			hightPos = (176 + Math.abs(random.nextInt(39))); // 获取高位值
			lowPos = (161 + Math.abs(random.nextInt(93))); // 获取低位值
			byte[] b = new byte[2];
			b[0] = (new Integer(hightPos).byteValue());
			b[1] = (new Integer(lowPos).byteValue());
			try {
				str = new String(b, "gb2312"); // 转成中文
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			ret += str;
		}
		return ret;
	}

}
